package Method_References;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;

public class number8 {
	public static void main(String[] args) {
		// 准备牌
		ArrayList<String> poker = new ArrayList<String>();

		// 定义一个哈希表存储大小
		HashMap<String, Integer> map = new HashMap<>();

		// 定义一个value值区分大小
		int value = 2;
		// 定义两个数组
		String[] colors = { "♠", "♣", "♥", "♦" };
		String[] numbers = { "2", "A", "K", "Q", "J", "10", "9", "8", "7", "6", "5", "4", "3" };
		poker.add("大王");
		poker.add("小王");
		// 将大小王添加入哈希表
		map.put("大王", 0);
		map.put("小王", 1);
		// 组装52张牌
		for (String number : numbers) {
			for (String color : colors) {
				poker.add(color + number);
				map.put(color + number, value);
				value++;
			}
		}
		// 展示所有牌
		System.out.println(poker);
		// 展示牌值
		System.out.println(map);
		// 洗牌
		Collections.shuffle(poker);

		Player playe1 = new Player("老王");
		Player playe2 = new Player("老李");
		Player playe3 = new Player("老刘");
		// 摸牌
		for (int i = 0; i < poker.size(); i++) {
			// 每一张牌
			String p = poker.get(i);
			if (i <= 51) {
				if (i % 3 == 0) {
					playe1.getList().add(p);
				} else if (i % 3 == 1) {
					playe2.getList().add(p);
				} else {
					playe3.getList().add(p);
				}
			}
		}
		// 看牌
		System.out.println(playe1.getName() + ":" + sortbyvalue(map, playe1.getList()));
		System.out.println(playe2.getName() + ":" + sortbyvalue(map, playe2.getList()));
		System.out.println(playe3.getName() + ":" + sortbyvalue(map, playe3.getList()));
	}

	public static ArrayList<String> sortbyvalue(HashMap<String, Integer> map, List<String> list) {
		List<String> sortedList = list.stream().sorted(Comparator.comparingInt(map::get).reversed())
				.collect(Collectors.toList());
		return new ArrayList<>(sortedList);
	}
}
